<?php

namespace app\middleware;

use app\log\CountReqTime;
use app\log\LogHandle;
use app\log\UserLog;
use  \think\facade\Log;
use think\Request;

class WriteReqLog
{
    /**
     * @param Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, \Closure $next)
    {
        //获取请求参数
        $data = [
            'params' => $request->param(),
            'get_params' => $request->get(),
            'post_params' => $request->post(),
            'method' => $request->method(),
            'url' => $request->url(),
        ];
        UserLog::Info("client请求参数", $data);

        return $next($request);
    }

    public function end(\think\Response $response)
    {
        // 回调行为
        CountReqTime::setLogCount();
    }
}